/*
 * @Author: lc
 * @version: v1.2
 * @Date: 2021-10-26 13:54:05
 * @LastEditors: lc
 * @LastEditTime: 2021-10-26 14:53:42
 * @Descripttion:
 */
var projectname = process.argv[3]
var glob = require('glob')

function getEntry() {
  var entries = {}
  if (process.env.NODE_ENV == 'production') {
    entries = {
      index: {
        // page的入口
        entry: 'src/pages/' + projectname + '/main.js',
        // 模板来源
        template: 'public/index.html',
        // 在 dist/index.html 的输出
        filename: 'index.html',
        title: projectname,
        chunks: ['chunk-vendors', 'chunk-common', 'index']
      }
    }
  } else {
    var items = glob.sync('./src/pages/*/*.js')
    for (var i in items) {
      var filepath = items[i]
      var fileList = filepath.split('/')
      var fileName = fileList[fileList.length - 2]
      entries[fileName] = {
        entry: `src/pages/${fileName}/main.js`,
        // 模板来源
        template: `public/index.html`,
        // 在 dist/index.html 的输出
        filename: `${fileName}.html`,
        // 提取出来的通用 chunk 和 vendor chunk。
        chunks: ['chunk-vendors', 'chunk-common', fileName]
      }
    }
  }
  console.log(entries)
  return entries
}

var pages = getEntry()

module.exports = {
  productionSourceMap: false, // 生产禁止显示源代码
  outputDir: 'dist/' + projectname,
  pages: pages,
  devServer: {
    open: true, //  npm run serve 自动打开浏览器
    port: 9999,
    index: '/projectA.html' // 默认启动serve 打开projectA页面
  }
}
